$(function () {
    $("#div2").hide()
    $("#gxbtg").bootstrapTable({
        method:"post",
        contentType:'application/json',
        url:"/DFile/shbtg",
        striped:true,
        pageNumber:1,
        pagination:true,
        sidePagination:'server',
        pageSize:3,
        pageList:[2,3,5,6],
        queryParams:function (parmes) {
            return{
                pageNum:(parmes.offset / parmes.limit) + 1,
                pageSize:parmes.limit,
            }
        },
        columns:[
            {title:"设计单编号",field:"designId",align:'center'},
            {title:"产品编号",field:"productId",align:'center'},
            {title:"产品名称",field:"productName",align:'center'},
            {title:"设计人",field:"designer",align:'center'},
            {title:"登记时间",field:"registerTime",align:'center'},
            {title:"工时总成本",field:"costPriceSum",align:'center'},
            {title:"变更",field:"costPriceSum",align:'center',
                formatter:function (value,row,index) {
                    var a="<a href='#' onclick='gxddgb("+JSON.stringify(row)+")'>变更</a>";
                    return a;
                }
            },
        ]
    })
})

function gxddgb(a) {
    $("#div1").hide();
    $("#div2").show();

    $("#name").html(a.productName);
    $("#bh").html(a.productId);
    $("[name=designer]").val(a.designer);
    $("[name=moduleCostPriceSum]").val(a.costPriceSum);
    $("[name=registerTime]").html(a.registerTime);
    $("[name=register]").val(a.register)
    $("#comment").val(a.procedureDescribe);

    $.ajax({
        type:"post",
        contentType:"application/json;charset:utf-8",
        url:"/DFile/cxgxmx/"+a.id,
        dataType:"json",
        async:true,
        success:function (data) {
            let tab = document.getElementById("gxtab");
            tab.innerHTML='';
            for (let i=0;i<data.length;i++){
                tab.innerHTML+="<tr><td>"+data[i].detailsNumber+"</td><td>"+data[i].procedureName+"</td><td><label class='gxbh'>"+data[i].procedureId+"</label></td><td class='ms'>"+data[i].procedureDescribe+"" +
                    "<td><input class='gsh' value='"+data[i].labourHourAmount+"'></td><td><input value='"+data[i].amountUnit+"' class='dw'></td>" +
                    "<td><input value='"+data[i].costPrice+"' class='dwcb'></td><td><a href='#' onclick='delgx("+data[i].id+")'>删除</a></td></tr>"
            }
        }
    })

}
//删除不需要的工序
function delgx(a) {}

function fh(){
    $("#div1").show();
    $("#div2").hide();
    $("#gxbtg").bootstrapTable("refresh");
}

function qd() {

    let sjr = $("[name=designer]").val();
    var sjyq = $("#comment").val();
    //工序编号
    let gxbh = $(".gxbh");
    //工时数
    let gs = $(".gsh");
    //单位
    let dw = $(".dw");
    //描述
    let ms = $(".ms");
    //单位总成本
    let dwcb = $(".dwcb");

    let zcb = 0;
    let arr1 = [];
    for (let i = 0; i < gs.length; i++) {
        let cb = 0;
        cb = parseInt(cb) + parseInt(gs[i].value * dwcb[i].value);
        zcb += cb;
        let gxmx1 = {
            procedureId: gxbh[i].innerHTML,
            labourHourAmount: gs[i].value,
            procedureDescribe: ms[i].innerHTML,
            amountUnit: dw[i].value,
            costPrice: dwcb[i].value,
            subtotal: cb,
        }
        arr1[i] = gxmx1;
    }

    let bhid = $("#bh").html();
    let gxzong = {
        productId: bhid,
        designer: sjr,
        costPriceSum: zcb,
        procedureDescribe: sjyq,
        list: arr1
    };
    if (confirm("确定提交变更吗？")){
        $.ajax({
            type: "put",
            contentType: "application/json;charset:utf-8",
            url: "/DFile/gxmxxiugai",
            data: JSON.stringify(gxzong),
            async: true,
            success: function (data) {
                $("#div1").show();
                $("#div2").hide();
                $("#gxbtg").bootstrapTable("refresh");
            }
        })
    }
}

function fh(){
    $("#div1").show();
    $("#div2").hide();
    $("#gxbtg").bootstrapTable("refresh");
}